// LOGIN.JAVA

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;


public class Login extends HttpServlet 
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
 public void init(ServletConfig sc)throws ServletException
	    {
		super.init(sc);
		try
                   	 {
                        
			System.out.println("Inside try");
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			con=DriverManager.getConnection("jdbc:odbc:psi","psi","psi");
			stmt=con.createStatement();
		     }
		catch(Exception e)
		{
			System.out.println(e);
		}
             }


public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
	{
               
		System.out.println("inside servise");
		String empid,pass,temp="";
        		PrintWriter out=res.getWriter();
 
		try
                  	 {
			empid=req.getParameter("empid");
			pass=req.getParameter("pass");
		System.out.println("empid:"+empid+"  :pass:   "+pass);
		
rs=stmt.executeQuery("select emp_code,emp_name from employee where emp_code='"+empid+"'  and emp_name='"+pass+"'");
        	        		System.out.println("After select statement");           
                			if(rs.next())
                   		{
			System.out.println("This is Login valid:"+rs.getString(1));
                  	      	res.sendRedirect("./contents.htm");     
     			}
			else{
                  	     	 System.out.println("invalid"); 
			res.sendRedirect("./invaild.htm");
			}
		}//try
		catch(Exception e){e.printStackTrace();}
                               
	}//service
}//class

	

